class Relation

      def self.many_to_many(options={})
          $child_connection = options[:parent_connection]
          $parent_connection = options[:child_connection]
          options.each{|key,value|
              if key.to_s != "parent_connection" && key.to_s != "child_connection" 
                    first_table = key[0]
                    first_table_primary_key = key[1]
                    if !key[2].nil?
                        first_table_connection = key[2]
                    else
                        first_table_connection = $parent_connection
                    end
                    second_table = value[0]
                    second_table_primary_key = value[1]
                    if !value[2].nil?
                        second_table_connection = value[2]
                    else
                        second_table_connection = $child_connection
                    end    
                    m_to_m_transform(first_table,first_table_primary_key,first_table_connection,second_table,second_table_primary_key,second_table_connection)
              end  
          }
      end      
  
  
      def self.one_to_many(options={})
          $child_connection = options[:child_connection]
          $parent_connection = options[:parent_connection]
          parent_table_array = options[:parent_table].split
          $parent_table = parent_table_array[0..(parent_table_array.index("with")-1)].join("_")
          $parent_table_primary_key = parent_table_array[(parent_table_array.index("with")+1)..parent_table_array.length-1].join("_")
          handle_primary_key($parent_table_primary_key,$parent_table,$parent_connection)
          options.each{|key,value|
              if !(["parent_connection","child_connection","parent_table"].include? key.to_s)
                    for child_tab_info in value
                        child_table = child_tab_info[0]
                        if !child_tab_info[1].nil?
                            child_table_connection = child_tab_info[1]
                        else
                            child_table_connection = $child_connection
                        end    
                        add_column_if_does_not_exists($parent_table_primary_key,child_table,child_table_connection)    
                        #~ child_table_connection.execute("ALTER TABLE #{child_table} ADD CONSTRAINT fk_const FOREIGN KEY (#{$parent_table_primary_key}) REFERENCES #{$parent_table}(#{$parent_table_primary_key}) ON DELETE CASCADE")
                    end    
              end  
          }
      end  
 
end